//Start functions of Model
var ModelTemplate = "templates/Model.xsl"

function loadModelData(){
	if(objectHTTPXML) {
		waitBox = new Lightbox.base('box1');
		objectHTTPXML.open('GET', '/model.load.model?m_id=' + modelID , true)
		objectHTTPXML.onreadystatechange = returnModelData
		objectHTTPXML.send(null)
	} else {
		alert("Your browser don't suport Ajax")
	}
}

function returnModelData(){
	if (objectHTTPXML.readyState == 4) {
		xml = objectHTTPXML.responseXML
		template = loadXSLfromXML(ModelTemplate, xml)
		document.getElementById("divBody").innerHTML = template
		waitBox.hideBox(null);
	}			
}

function saveModel(){
	if(objectHTTPXML) {
		var parameters = "m_id=" + modelID +
						 "&name=" + encodeURI(document.getElementById("name").value) +
						 "&author=" + encodeURI(document.getElementById("author").value) +
						 "&comments=" + encodeURI(document.getElementById("comments").value)
						 
		waitBox = new Lightbox.base('box1');

		objectHTTPXML.onreadystatechange = returnSaveModel
		objectHTTPXML.open('POST', '/model.save.model', true);
		objectHTTPXML.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		objectHTTPXML.setRequestHeader("Content-length", parameters.length);
		objectHTTPXML.setRequestHeader("Connection", "close");
		objectHTTPXML.send(parameters);
	} else {
		alert("Your browser don't suport Ajax")
	}
}

function returnSaveModel(){
	if (objectHTTPXML.readyState == 4) {
		waitBox.hideBox(null);
		if(objectHTTPXML.responseText == 'OK'){
			changeName('-1', document.getElementById("name").value)
			alert('Data saved!')
		} else {
			alert('Data not saved!')
			loadModelData()
		}
	}			
}

function exportModelToXMI(){
	window.open('/model.export.model?m_id=' + modelID,'Metamodel ' + document.getElementById('name').value,'left=20,top=20,width=500,height=500,toolbar=0,resizable=0');
}

//End functions of Model